package com.lyc.yuki.module.finance.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyc.yuki.common.result.ResponseResult;
import com.lyc.yuki.module.finance.domain.po.IncomeRecordsPO;
import com.lyc.yuki.module.finance.domain.vo.IncomeRecordsVO;
import com.lyc.yuki.module.finance.service.IncomeRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lyc
 * @Date: 2025/7/24 19:46
 */
@RestController
@RequestMapping("/finance/income")
public class IncomeRecordsController {

    @Autowired
    private IncomeRecordsService incomeRecordsService;

    @GetMapping("/page")
    public ResponseResult<IPage<IncomeRecordsVO>> page(@RequestParam(defaultValue = "1") Integer current,
                                                       @RequestParam(defaultValue = "10") Integer size) {
        Page<IncomeRecordsVO> page = new Page<>(current, size);
        IPage<IncomeRecordsVO> incomeRecordsVOIPage = incomeRecordsService.pageItem(page);
        return ResponseResult.successWithData(incomeRecordsVOIPage);
    }

    @DeleteMapping("/batchDelete")
    public ResponseResult<Boolean> batchDelete(@RequestBody List<Integer> ids) {
        boolean flag = incomeRecordsService.removeByIds(ids);
        return ResponseResult.successWithData(flag);
    }

    @PutMapping("/saveOrUpdate")
    public ResponseResult<Boolean> saveOrUpdate(@RequestBody IncomeRecordsPO incomeRecordsPO) {
        boolean flag = incomeRecordsService.saveOrUpdate(incomeRecordsPO);
        return ResponseResult.successWithData(flag);
    }
}
